/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function(nums, target) {
    let map=new Map()
    for(let i=0;i<nums.length;i++){
        let need=target-nums[i]
        if(map.get(need)>=0){
            return [map.get(need),i]
        }
        //否则记录map
        map.set(nums[i],i)
    }
    return -1
};
let nums = [2,7,11,15]
let target = 9
console.log(twoSum(nums,target)); //[0,1]